import 'package:auto_route/auto_route.dart';
import 'package:casdon/app/config/theme/theme_extention.dart';

import 'package:casdon/common/widget/common_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// 绑定结果页（仿 BindAccountResultViewController）
///
@RoutePage()
class TMBindResultScreen extends StatelessWidget {
  /// 为空表示成功；不为空时显示异常信息
  final String? errorMessage;

  const TMBindResultScreen({super.key, this.errorMessage});

  bool get _isSuccess => errorMessage == null || errorMessage!.isEmpty;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonAppBar(title: "绑定结果"),
      backgroundColor: Colors.white,
      body: SafeArea(
        child: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,

            children: [
              // 图示
              _buildStatusImage(),
              SizedBox(height: 24.h),
              // 标题
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 24.w),
                child: Text(
                  _isSuccess ? '激活语音功能，请使用手机号注册登录' : '绑定异常',
                  style: context.textTheme.titleMedium?.copyWith(
                    color: context.customColorThemeNonNull.textColor1,
                    fontSize: 16.r,
                  ),
                  textAlign: TextAlign.center,
                ),
              ),
              SizedBox(height: 10.h),
              // 描述
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 24.w),
                child: Text(
                  _isSuccess
                      ? '(请使用阿里系的注册手机号)'
                      : (errorMessage ?? '绑定失败，请稍后重试'),
                  style: context.textTheme.bodyMedium?.copyWith(
                    color: context.customColorThemeNonNull.textColor3,
                    fontSize: 13.r,
                  ),
                  textAlign: TextAlign.center,
                ),
              ),
              SizedBox(height: 500.h),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildStatusImage() {
    if (_isSuccess) {
      return CircleAvatar(
        radius: 22.5.r,
        backgroundColor: const Color(0xFF52C41A),
        child: Icon(Icons.check, color: Colors.white, size: 22.5.r),
      );
    }
    return CircleAvatar(
      radius: 22.5.r,
      backgroundColor: const Color(0xFFF5222D),
      child: Icon(Icons.close, color: Colors.white, size: 22.5.r),
    );
  }
}
